home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / CMPLTPAS / MOUSE.PAS < prev    next >
Pascal/Delphi Source File  |  1988-10-06  |  6KB  |  229 lines

  1. {--------------------------------------------------------------}
  2. {            TURBO PASCAL 4.0 MOUSE INTERFACE UNIT             }
  3. {                                                              }
  4. {                               by Jeff Duntemann              }
  5. {                               Turbo Pascal V4.0              }
  6. {                               Last Updated 10/26/87          }
  7. {                                                              }
  8. {     From the book, Complete Turbo Pascal, Third Edition      }
  9. {     Scott, Foresman & Company  ISBN                          }
  10. {--------------------------------------------------------------}
  11.  
  12. UNIT Mouse;
  13.  
  14. INTERFACE
  15.  
  16. USES DOS;
  17.  
  18.  
  19. VAR
  20.   ButtonCount : Integer;          { Number of buttons on mouse }
  21.  
  22.  
  23. FUNCTION IsLogitechMouse : Boolean;          { Looks at driver }
  24.  
  25. PROCEDURE ResetMouse;         { Standard Mouse function call 0 }
  26.  
  27. PROCEDURE PointerOn;                                       { 1 }
  28.  
  29. PROCEDURE PointerOff;                                      { 2 }
  30.  
  31. PROCEDURE PollMouse(VAR X,Y : Word;
  32.                     VAR Left,Center,Right : Boolean);      { 3 }
  33.  
  34. PROCEDURE PointerToXY(X,Y : Word);                         { 4 }
  35.  
  36. PROCEDURE SetColumnRange(High,Low : Word);                 { 7 }
  37.  
  38. PROCEDURE SetRowRange(High,Low : Word);                    { 8 }
  39.  
  40. {PROCEDURE MouseCall(VAR M1,M2,M3,M4 : Word); }
  41.  
  42.  
  43.  
  44. {--------------------------------------------------------------}
  45. {                  MOUSE UNIT IMPLEMENTATION                   }
  46. {                                                              }
  47. {  Note that I choose to re-assert the parameter lists in the  }
  48. {  implementation.  It causes no harm and makes this easier    }
  49. {  to read, so why not?  Also note that here, the low-level    }
  50. {  mouse-call procedure Mouser is private to the unit and      }
  51. {  can't be called from outside the unit.  If you wish to do   }
  52. {  more exotic things with the mouse driver (like turn the     }
  53. {  worthless light pen emulation on or off) you should move    }
  54. {  Mouser into the interface to make it accessible.            }
  55. {--------------------------------------------------------------}
  56.  
  57. IMPLEMENTATION
  58.  
  59.  
  60. VAR
  61.   M1,M2,M3,M4 : Word;
  62.  
  63.  
  64.  
  65. PROCEDURE MouseCall(VAR M1,M2,M3,M4 : Word);
  66.  
  67. VAR
  68.   Regs : Registers;
  69.  
  70. BEGIN
  71.   WITH Regs DO
  72.     BEGIN
  73.       AX := M1; BX := M2; CX := M3; DX := M4
  74.     END;
  75.   Intr(51,Regs);
  76.   WITH Regs DO
  77.     BEGIN
  78.       M1 := AX; M2 := BX; M3 := CX; M4 := DX
  79.     END
  80. END;
  81.  
  82.  
  83. FUNCTION NumberOfMouseButtons : Integer;
  84.  
  85. BEGIN
  86.   M1 := 0;  { Must reset mouse to count buttons! }
  87.   MouseCall(M1,M2,M3,M4);
  88.   NumberOfMouseButtons := M2
  89. END;
  90.  
  91.  
  92.  
  93. FUNCTION MouseIsInstalled : Boolean;
  94.  
  95. TYPE
  96.   BytePtr = ^Byte;
  97.  
  98. VAR
  99.   TestVector : BytePtr;
  100.  
  101. BEGIN
  102.   GetIntVec(51,Pointer(TestVector));
  103.   { $CF is the binary opcode for the IRET instruction; }
  104.   { in many BIOSes, the startup code puts IRETs into   }
  105.   { most unused bectors. }
  106.   IF (TestVector = NIL) OR (TestVector^ = $CF) THEN
  107.     MouseIsInstalled := False
  108.   ELSE
  109.     MouseIsInstalled := True
  110. END;
  111.  
  112.  
  113. {--------------------------------------------------------------}
  114. {      PROCEDURES ABOVE THIS BAR ARE PRIVATE TO THIS UNIT      }
  115. {--------------------------------------------------------------}
  116.  
  117.  
  118.  
  119. FUNCTION IsLogitechMouse : Boolean;
  120.  
  121. TYPE
  122.   Signature = ARRAY[0..13] OF Char;
  123.   SigPtr = ^Signature;
  124.  
  125. CONST LogitechSig : Signature = 'LOGITECH MOUSE';
  126.  
  127. VAR
  128.   TestVector : SigPtr;
  129.   L          : LongInt;
  130.  
  131. BEGIN
  132.   GetIntVec(51,Pointer(TestVector));
  133.   LongInt(TestVector) := LongInt(TestVector) + 16;
  134.   IF TestVector^ = LogitechSig THEN
  135.     IsLogitechMouse := True
  136.   ELSE
  137.     IsLogitechMouse := False
  138. END;
  139.  
  140.  
  141.  
  142. PROCEDURE ResetMouse;
  143.  
  144. BEGIN
  145.   M1 := 0;
  146.   MouseCall(M1,M2,M3,M4);
  147. END;
  148.  
  149.  
  150. PROCEDURE PointerOn;
  151.  
  152. BEGIN
  153.   M1 := 1;
  154.   MouseCall(M1,M2,M3,M4)
  155. END;
  156.  
  157.  
  158. PROCEDURE PointerOff;
  159.  
  160. BEGIN
  161.   M1 := 2;
  162.   MouseCall(M1,M2,M3,M4)
  163. END;
  164.  
  165.  
  166. PROCEDURE PollMouse(VAR X,Y : Word; VAR Left,Center,Right : Boolean);
  167.  
  168. BEGIN
  169.   M1 := 3;              { Perform mouse function call 3 }
  170.   MouseCall(M1,M2,M3,M4);
  171.   X := M3; Y := M4;     { Return mouse pointer X,Y position }
  172.   IF (M2 AND $01) = $01 THEN Left := True ELSE Left := False;
  173.   IF (M2 AND $02) = $02 THEN Right := True ELSE Right := False;
  174.   IF (M2 AND $04) = $04 THEN Center := True ELSE Center := False;
  175. END;
  176.  
  177.  
  178. PROCEDURE PointerToXY(X,Y : Word);
  179.  
  180. BEGIN
  181.   M1 := 4;
  182.   M3 := X; M4 := Y;
  183.   MouseCall(M1,M2,M3,M4)
  184. END;
  185.  
  186.  
  187. PROCEDURE SetColumnRange(High,Low : Word);
  188.  
  189. BEGIN
  190.   M1 := 7;
  191.   M3 := Low;
  192.   M4 := High;
  193.   MouseCall(M1,M2,M3,M4)
  194. END;
  195.  
  196.  
  197. PROCEDURE SetRowRange(High,Low : Word);
  198.  
  199. BEGIN
  200.   M1 := 8;
  201.   M3 := Low;
  202.   M4 := High;
  203.   MouseCall(M1,M2,M3,M4)
  204. END;
  205.  
  206.  
  207. {--------------------------------------------------------------}
  208. {                   INITIALIZATION SECTION                     }
  209. {                                                              }
  210. {  Function MouseIsInstalled goes out and checks the interrupt }
  211. {  51 vector--if it is either NIL (zeroed) or points to an     }
  212. {  IRET, the mouse is assumed NOT to be installed.  Note that  }
  213. {  a vector table full of garbage may be taken to mean the     }
  214. {  mouse driver is there.  Use the VECTORS utility to check    }
  215. {  the state of your vector table after cold boot.  Some Asian }
  216. {  schlock BIOSes may not initialize the table properly and    }
  217. {  cause a false reading on testing for an installed driver.   }
  218. {--------------------------------------------------------------}
  219.  
  220.  
  221. BEGIN
  222.   IF NOT MouseIsInstalled THEN
  223.     BEGIN
  224.       Writeln('>>>ERROR:  Mouse driver not detected.  Aborting to DOS.');
  225.       HALT(1)
  226.     END;
  227.   ButtonCount := NumberOfMouseButtons
  228. END.  {Mouse}
  229.